﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Yglu.TerminalApp
{
	public partial class PopupForm : Form
	{
		#region Properties

		public Boolean IsError { get; set; }
		public String Title { get; set; }
		public String Description { get; set; }

		#endregion

		#region Main methods

		public PopupForm(Boolean isError, String msg)
		{
			InitializeComponent();

			IsError = isError;
			Description = msg;
		}

		private void PopupForm_Load(object sender, EventArgs e)
		{
			lblMessage.Text = Description;

			if (IsError)
			{
				BackColor = Color.Red;
				lblTitle.Text = Messages.Warning;
			}
			else
			{
				BackColor = Color.SkyBlue;
				lblTitle.Text = Messages.Confirmation;
			}
		}

		private void timerClose_Tick(object sender, EventArgs e)
		{
			Opacity = Opacity - 0.05;

			if (Opacity < 0.02)
			{
				Close();
			}

			timerClose.Interval = 50;

			Application.DoEvents();
		}

		private void PopupForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape)
			{
				Close();
			}
		}

		private void PopupForm_MouseDown(object sender, MouseEventArgs e)
		{
			Close();
		}

		#endregion
	}
}